from selenium import webdriver
from pprint import pprint

# 打开浏览器,请求目标网址
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

pprint(driver.get_cookies())  # 打印获取的所有cookie信息
# driver.get_cookie(name)  返回指定name的cookie信息
pprint(driver.get_cookie('BA_HECTOR'))

# 添加cookie, 必须有name和value
# driver.add_cookie(字典)
dict1 = {'name': 'hello', 'value': '111111'}
driver.add_cookie(dict1)
pprint(driver.get_cookies())

# 删除指定name的cookie信息
driver.delete_cookie('hello')
pprint(driver.get_cookies())

# 删除所有cookie信息
driver.delete_all_cookies()
pprint(driver.get_cookies())

# 退出浏览器
driver.quit()
